﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using TradeCore;
using TradeCore.Model;
using TradeCore.Quote;

namespace TradeCoreTest
{
    class Program
    {
        static void Main(string[] args)
        {
            CoreTest test = new CoreTest();

            test.init();

            while (true)
            {
                System.Threading.Thread.Sleep(200);
            }
        }
    }

    class CoreTest
    {
        private QuoteManager quoteManager;

        public void init()
        {
            quoteManager = QuoteManager.GetInstance();

            KLineSeries kSeries = new KLineSeries(MarketType.Futures, "ru1301", 1, KLineUnit.Minutes);

            kSeries.PriceUpdate += kSeries_PriceChange;

            TestPolicy policy = new TestPolicy();
            kSeries.RegPolicy(policy);

            quoteManager.Add(kSeries);

            CoreManager coreManager = new CoreManager();
            coreManager.StartQuote();
        }

        void kSeries_PriceChange(KLineSeries series)
        {
            //Console.WriteLine(series.Last.Close);
        }
    }

    public class TestPolicy : PolicyBase
    {
        /// <summary>
        /// 策略名称
        /// </summary>
        public override string PolicyName { get { return "Test Policy"; } }

        /// <summary>
        /// K线更新事件
        /// </summary>
        /// <param name="series">引发事件K线序列</param>
        public override void PriceUpdate(KLineSeries series)
        {
            Console.WriteLine("PriceChange: " + series.Last.Close);
        }

        /// <summary>
        /// K线完成事件
        /// </summary>
        /// <param name="series">引发事件K线序列</param>
        public override void KLineFinished(KLineSeries series)
        {
            Console.WriteLine("KLineFinished: " + series.Last.Close);
        }

        /// <summary>
        /// K线新开事件
        /// </summary>
        /// <param name="series">引发事件K线序列</param>
        public override void KLineOpen(KLineSeries series)
        {
            Console.WriteLine("KLineOpen: " + series.Last.Close);
        }
    }
}
